import { isEditorENV, InbizIcon } from '@inbiz/utils';
import { routerPrefix } from 'InbizConfig';
import React from 'react';
import TitleLogo from '../TitleLogo';

type TitleProps = {
  IsNew?: boolean;
  Title: string;
  listLogo?: string;
  showCate?: boolean;
  newsKey: News.INewsCateValueType;
  detail?: string;
  ID: string;
  IsTop?: boolean;
  tagType: string;
  ContentUrl?: any;
  ContentCategory:any;
  ContentCategoryName:any;
};

const Title: React.FC<TitleProps> = (props) => {
  const { Title, IsNew, listLogo, showCate, newsKey, detail, ID, IsTop, tagType, ContentUrl,ContentCategory,ContentCategoryName } =
    props;
  const prefixCls = 'inbiz-News-title';

  const jumpToDetail = () => {
    const { origin, pathname, search } = window.location;
    // 设计器环境
    if (isEditorENV()) {
      return;
    }
    if (!!ContentUrl) {
      window.open(ContentUrl);
      return;
    }
    if (!detail) return;
    const [name] = detail.split(',');
    window.open(
      `${origin}${pathname}${search}#${routerPrefix}${name}?newsId=${ID}&cateId=${ContentCategory}`,
    );
  };
  return (
    <div className={`${prefixCls} ${prefixCls}-${tagType}`} onClick={jumpToDetail} title={Title}>
      {listLogo && <TitleLogo listLogo={listLogo} />}
      {showCate && <span>【{ContentCategoryName}】</span>}
      <span className={`${prefixCls}-content content-${tagType}`}>
        <div className={`${prefixCls}-nav`}>{Title}</div>
        <div className={`${prefixCls}-tag tag-${tagType} tag-multiple`}>
          {IsNew && <InbizIcon type='icon-NEW' />}
          {IsTop && <InbizIcon type='icon-TOP' />}
        </div>
      </span>
    </div>
  );
};

export default Title;
